﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DataAccess;
namespace XuaNhapKho
{
    public partial class KhoHang : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["User"] == null)
                {
                    Response.Redirect("/Default.aspx");
                }
                else
                {
                    
                }

                loadGridView();

                DataSet ds = KhoDAO.GetReport();
                
                foreach(DataRow rows in ds.Tables[0].Rows) 
                {
                    ltlTongHang.Text = rows["TongHang"].ToString();
                    
                    ltlTongTienKho.Text = String.Format("{0:0,0}", double.Parse(rows["TongTienTrongKho"].ToString()));
                }



            }
        }

        public void loadGridView()
        {
            grvKho.DataSource = KhoDAO.GetAll();
            grvKho.DataBind();
        }
        protected void grvKho_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grvKho.PageIndex = e.NewPageIndex;
            loadGridView();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            grvKho.DataSource = KhoDAO.GetBy(txtMaSanPham.Text);
            grvKho.DataBind();
        }
    }
}